<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>数据代理-Object.defineProperty方法</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="root">

  </div>
  <script>

    let number = 18


    let person = {
      name: 'ZS',
      sex: 'male'
    }

    Object.defineProperty(person, 'age', {
      // value: 18,
      // enumerable:true,    // 控制属性是否可以枚举，默认值是false
      // writable:true,      // 控制属性是否可以被修改，默认值是false
      // configurable:true,  // 控制属性是否可以被删除，默认值是false

      get: function () {
        return number
      },

      set(value) {
        console.log('The age is changed to', value)
        number = value
      }

    })
    console.log(person)

  </script>
</body>

</html>